package ac.svn.accesscontrol.ui.renderer;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import ac.svn.accesscontrol.manager.SVNInfoManager;
import ac.svn.accesscontrol.store.AccessUnit;
import ac.svn.accesscontrol.store.SVNUser;
import ac.svn.accesscontrol.ui.AccessUnitListCell;
import ac.svn.accesscontrol.utils.Utility;

public class AccessListCellRenderer extends AccessUnitListCell implements
ListCellRenderer {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public AccessListCellRenderer() {
	super();

    }

    @Override
    public Component getListCellRendererComponent(JList arg0, Object value,
	    int arg2, boolean isSelected, boolean arg4) {

	AccessUnit accessUnit = (AccessUnit) value;
	String title = accessUnit.getOwnerId();
	if(true == SVNInfoManager.getInfoManager().isAGroup(accessUnit.getOwnerId()))	{

	}else{
	    SVNUser svnUser = SVNInfoManager.getInfoManager().getSvnUser(accessUnit.getOwnerId());
	    if(null != svnUser){
		title = svnUser.getUserName();
	    }
	}

	setTitle(title);
	setSelected(isSelected);
	setAccess(accessUnit.isReadEnabled(),accessUnit.isWriteEnabled());
	Icon icon = Utility.getImageIcon("images/access.png");
	setIcon(icon);		
	return this;
    }

}
